package com.photoeditor.demo.ui.activity.effect;

import android.animation.Animator;
import android.animation.AnimatorListenerAdapter;
import android.animation.ObjectAnimator;
import android.animation.ValueAnimator;
import android.app.Activity;
import android.app.Fragment;
import android.content.Intent;
import android.graphics.Bitmap;
import android.graphics.Paint;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v4.view.ViewPager;
import android.text.Spannable;
import android.text.SpannableString;
import android.text.TextUtils;
import android.text.style.ScaleXSpan;
import android.util.Log;
import android.util.TypedValue;
import android.view.View;
import android.view.ViewGroup;
import android.widget.Filter;
import android.widget.ImageView;
import android.widget.RelativeLayout;
import android.widget.ScrollView;
import android.widget.TextView;
import android.widget.Toast;

import com.bumptech.glide.request.target.Target;
import com.common.base.log.RLog;
import com.common.base.utils.DebugUtil;
import com.common.base.utils.DeviceUtils;
import com.common.base.utils.thread.ThreadPool;
import com.common.commercialize.ad.AdDisplay;
import com.common.commercialize.ad.AdManager;
import com.common.commercialize.reward.RewardAdManager;
import com.common.commercialize.sdk.CommercializeSDK;
import com.photoeditor.R;
import com.photoeditor.demo.ad.AdItemBean;
import com.photoeditor.demo.ad.AdKeyConstant;
import com.photoeditor.demo.ad.AdProvider;
import com.photoeditor.demo.app.TestUser;
import com.photoeditor.demo.app.XActivity;
import com.photoeditor.demo.db.DataManager;
import com.photoeditor.demo.imageloader.GlideApp;
import com.photoeditor.demo.model.event.CheckFloatWindowPermissionEvent;
import com.photoeditor.demo.model.event.DownloadFinishEvent;
import com.photoeditor.demo.model.event.FilterDetailUnlockSuccess;
import com.photoeditor.demo.model.event.RefreshFilterCategory;
import com.photoeditor.demo.model.event.RefreshStickerEvent;
import com.photoeditor.demo.model.event.SubscribeSuccessEvent;
import com.photoeditor.demo.model.preference.SPDataManager;
import com.photoeditor.demo.model.preference.SpConstant;
import com.photoeditor.demo.model.preference.SpUtils;
import com.photoeditor.demo.model.sticker.StickerUnlockData;
import com.photoeditor.demo.model.store.download.DownloadUtils;
import com.photoeditor.demo.model.store.download.IDownloadListener;
import com.photoeditor.demo.model.store.module.BaseOnlineManager;
import com.photoeditor.demo.model.store.module.HomeOnlineManager;
import com.photoeditor.demo.model.store.module.StoreOnlineBean;
import com.photoeditor.demo.model.store.module.StoreOnlineManager;
import com.photoeditor.demo.ui.activity.face.FaceLogicActivity;
import com.photoeditor.demo.ui.dialog.DialogShow;
import com.photoeditor.demo.ui.dialog.DialogStatistic;
import com.photoeditor.demo.ui.dialog.IAdVideoDialogListener;
import com.photoeditor.demo.ui.dialog.IDialog;
import com.photoeditor.demo.ui.dialog.WDialogShow;
import com.photoeditor.demo.util.AppOpenUtil;
import com.photoeditor.demo.util.NetworkUtils;
import com.photoeditor.demo.util.ToastUtil;
import com.photoeditor.demo.util.store.StoreConstant;
import com.photoeditor.demo.ui.widget.RenderingView;
import com.photoeditor.demo.ui.activity.GalleryActivity;
import com.photoeditor.demo.model.subscribe.manager.AppVipManager;
import com.photoeditor.demo.model.subscribe.manager.SVipController;
import com.photoeditor.demo.statistics.NotifyStoreUpdateStatisticUtil;
import com.photoeditor.demo.statistics.StatisticsConstant;
import com.photoeditor.demo.statistics.StatisticsUtils;
import com.photoeditor.demo.ui.activity.GalleryActivity;
import com.photoeditor.demo.ui.activity.edit.EditorImageActivity;
import com.photoeditor.demo.ui.adapter.effect.FilterDetailPagerAdapter;
import com.photoeditor.demo.ui.widget.ChangeableRectButton;
import com.photoeditor.demo.ui.widget.ObservableVerticalScrollView;
import com.photoeditor.demo.ui.widget.RenderingView;
import com.photoeditor.demo.ui.widget.RoundRectProgressView;
import com.photoeditor.demo.util.AppOpenUtil;
import com.photoeditor.demo.util.AsyncTask;
import com.photoeditor.demo.util.BitmapCache;
import com.photoeditor.demo.util.FastBlur;
import com.photoeditor.demo.util.FontUtil;
import com.photoeditor.demo.util.PermissionUtil;
import com.photoeditor.demo.util.PluginVersionUtil;
import com.photoeditor.demo.util.TimeConstant;
import com.photoeditor.demo.util.store.StoreConstant;
import com.photoeditor.demo.util.transformation.BlurTransformation;

import org.greenrobot.eventbus.EventBus;
import org.greenrobot.eventbus.Subscribe;
import org.greenrobot.eventbus.ThreadMode;

import java.lang.ref.WeakReference;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.concurrent.CopyOnWriteArrayList;
import java.util.concurrent.ExecutionException;

import butterknife.Bind;
import butterknife.ButterKnife;
import butterknife.OnClick;

import static com.photoeditor.demo.model.preference.SpUtils.EFFECT_NAME;
import static com.photoeditor.demo.model.preference.SpUtils.FILTERDETAILUNLOCK;
import static com.photoeditor.demo.model.preference.SpUtils.ISFROMBUTTON;
import static com.photoeditor.demo.model.subscribe.manager.SVipConstant.VIP_ENTRANCE_EDIT;
import static com.photoeditor.demo.ui.adapter.home.HomeAdapter.isIsShowVipView;

//import com.photoeditor.demo.ui.dialog.DownloadAdDialog;
//import com.photoeditor.demo.ui.dialog.DownloadDialogFragment;

/**
 * Created by Administrator on 2017/5/11 0011.
 */

public class FilterDetailActivity extends XActivity implements ObservableVerticalScrollView.OnScrollChangedListener, FilterDetailPagerAdapter.StartBlurListener {

    private static final String EXTRA_STORE_ONLINE_BEAN = "EXTRA_STORE_ONLINE_BEAN";
    private static final String EXTRA_ENTRANCE = "mEntrance";

    private static final int DOWNLOAD_STATUS_NO = 0;
    private static final int DOWNLOAD_STATUS_ING = 1;
    private static final int DOWNLOAD_STATUS_OVER = 2;
    private int mDownloadStatus = DOWNLOAD_STATUS_NO;
    private static int SCROLL_LENGTH = 100;
    private float spacing = 1.5f;
    @Bind(R.id.scroll_view)
    ObservableVerticalScrollView mScrollView;
    @Bind(R.id.category_detail_bg)
    ImageView mBackGround;
    @Bind(R.id.iv_category_details_back)
    ImageView mBackBtn;
    @Bind(R.id.tv_category_title)
    TextView mCategoryTitle;
    @Bind(R.id.tv_filter_title)
    TextView mFilterTitle;
    @Bind(R.id.tv_filter_author)
    TextView mFilterAuthor;
    @Bind(R.id.tv_filter_desc)
    TextView mFilterDesc;
    @Bind(R.id.vp_category_detail)
    ViewPager mViewPager;
    @Bind(R.id.iv_category_download)
    RelativeLayout mDownloadBtn;
    @Bind(R.id.progress_view)
    RoundRectProgressView mProgressView;
    @Bind(R.id.download_text)
    RelativeLayout downloadText;
    @Bind(R.id.iv_download)
    TextView mBottomIcon;
    @Bind(R.id.btn_watch_ad)
    ChangeableRectButton mWatchADBtn;
    @Bind(R.id.ad_layout)
    ViewGroup mAdLayout;
    @Bind(R.id.ad_view)
    ViewGroup mDownloadAdLayout;
    @Bind(R.id.ad_mask)
    View mDownloadAdMask;

    private String mCategoryId;
    private boolean isFreeToUnlock=false;
    private ArrayList<StoreOnlineBean> mStoreOnlineBeanList;
    private int mCurrentItem = 0;
    private FilterDetailPagerAdapter mPagerAdapter;
    private BlurTransformation blurTransformation;

    private IDownloadListener mDownloadListener;

    private StoreOnlineBean mFilterBean;
    private ValueAnimator valueAnimator;
    private BitmapCache mBitmapCache;
    private HashMap<String, AsyncTask> tasks = new HashMap<>();
    private AppOpenUtil mAppJump;



    private boolean mIsNeedShowDownloadAd = true;
    //    private AdManager.Loader mAdLoader;
    private boolean mSubstituteAdReady = false;
    private boolean mAllRewardAdFail = false;
    //    private AdManager.Loader mRewardLoader;
    private String mDownloadAdKey; // 下载滤镜广告对应的cache key
    private String mSubstituteAdKey; // 替补广告对应的cache key

    // 区分主页还是商店
    private int mEntrance;
    public static final int ENTRANCE_STORE = 0;
    public static final int ENTRANCE_HOME = 1;

    // 进入商店的入口
    private int mStoreEntrance;
    private boolean mNeedBuy = false;
    private View mAdView;
    private boolean isNeedExitAd = true;
//    private AdProvider mInListAdProvider;
//    private AdItemBean mLayoutAdItemBean;

    private AdProvider mAdProvider;
    private String adCacheKey;

    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_filter_detail);
        ButterKnife.bind(this);
        Intent intent = getIntent();
        dealIntent(intent);

        EventBus.getDefault().register(this);
    }

    @Override
    protected void onNewIntent(Intent intent) {
        super.onNewIntent(intent);
        // 更新本地的intent，否则getIntent()返回的是最初的
        setIntent(intent);
//        Fragment fragment = getFragmentManager().findFragmentByTag(DownloadAdDialog.TAG_DOWNLOAD_DIALOG);
//        if (fragment instanceof DownloadDialogFragment) {
//            ((DownloadDialogFragment) fragment).dismiss();
//        }
        dealIntent(intent);
    }

    private void dealIntent(Intent intent) {
        StatisticsUtils.statisicsCustomFunction("detail_in", "where", "category");

        if (intent != null) {
            mStoreEntrance = intent.getIntExtra(StoreConstant.store.EXTRA_STORE_ENTRANCE
                    , StoreConstant.store.storeEntrance.ENTRANCE_NO);
            mEntrance = intent.getIntExtra("mEntrance", ENTRANCE_STORE);
            mFilterBean = (StoreOnlineBean) intent.getSerializableExtra(EXTRA_STORE_ONLINE_BEAN);
        }
        initData();
        if (mFilterBean == null) {
            finish();
            return;
        }
        mBitmapCache = new BitmapCache(this);
        mAppJump = new AppOpenUtil(this);
        initView();
        initInListAd();
        initDownload();
        initRewardedVideoAd();

        if (mIsNeedShowDownloadAd) {
            loadDownloadAd();
        }
    }


    @Override
    protected void onResume() {
        super.onResume();
//        EventBus.getDefault().register(this);
    }

    @Override
    protected void onPause() {
        super.onPause();
//        EventBus.getDefault().unregister(this);
    }

    private void initView() {
        blurTransformation = new BlurTransformation(getApplicationContext(), 23);
        FontUtil.setCustomFont(mFilterDesc);
        FontUtil.setCustomFontBold(mCategoryTitle, mFilterTitle);
//        mCategoryTitle.setAllCaps(true);
//        mFilterTitle.setAllCaps(true);
        mFilterAuthor.getPaint().setFlags(Paint.UNDERLINE_TEXT_FLAG);
        mScrollView.setOnScrollChangedListener(this);
        String nameStr = mFilterBean.getName().replaceAll("[A-Z]", " $0");//正则替换注意“ $0”前面有个空格
        mCategoryTitle.setText(nameStr);

        mPagerAdapter = new FilterDetailPagerAdapter(this, mStoreOnlineBeanList, false, mFilterBean.getPkgName());
        mPagerAdapter.setListener(this);
        mViewPager.setAdapter(mPagerAdapter);
        ViewGroup.LayoutParams layoutParams = mViewPager.getLayoutParams();
        layoutParams.width = ViewGroup.LayoutParams.MATCH_PARENT;
        layoutParams.height = (int) ((DeviceUtils.getScreenWidthPx(this) - DeviceUtils.dip2px(this, 60f)) * 4f / 3f
                - DeviceUtils.dip2px(this, 80));
        mViewPager.setLayoutParams(layoutParams);
        mViewPager.setPageMargin(DeviceUtils.dip2px(this, 16));
        mViewPager.setOffscreenPageLimit(0);
        mViewPager.setCurrentItem(mCurrentItem);
        mViewPager.addOnPageChangeListener(new ViewPager.SimpleOnPageChangeListener() {

            @Override
            public void onPageSelected(int position) {
                if (mCurrentItem != position) {
                    mCurrentItem = position;
                    updateView();

                    StoreOnlineBean storeOnlineBean = mStoreOnlineBeanList.get(mCurrentItem);
                    String name = storeOnlineBean.getName();
                    StatisticsUtils.statisticsCustomStoreShow(StatisticsConstant.UMENG_CUSTOM_EVENT_FUNC_STORE_VALUE_CATEGORY_VIEW
                            + "_" + name);
                }
            }

            @Override
            public void onPageScrollStateChanged(int state) {
                if (state == ViewPager.SCROLL_STATE_DRAGGING) {
                    ImageView childAt = mPagerAdapter.getCurrentView(mCurrentItem);
                    if (childAt != null) {
                        if (childAt instanceof RenderingView && ((RenderingView) childAt).getProgress() == 0) {
                            ((RenderingView) childAt).startAnimator();
                        }
                    }
                }
            }
        });

        updateView();
        mProgressView.setMaxCount(100);
    }

    private void initDownload() {
        mDownloadListener = new DownloadListener(mFilterBean.getPkgName(), this);
        DownloadUtils.getInstance().addListener(mDownloadListener);
        boolean isApply = StoreOnlineManager.getInstance().isInstalledByPkgName(mFilterBean, mFilterBean.getType());

        //初始化下载按钮
        if (isApply) {
            updateUIOfInstall();
        } else if (isDownloading()) {
            int percent = DownloadUtils.getInstance().getPercentage(mCategoryId);
            mProgressView.setProgress(percent == 0 ? 1 : percent);
            mProgressView.setVisibility(View.VISIBLE);
            downloadText.setVisibility(View.VISIBLE);
            mWatchADBtn.setVisibility(View.GONE);
        } else {
            updateUIOfUninstall();
        }
    }

    private void initRewardedVideoAd() {
        // 首先判断滤镜分类是否需要付费
        if (mFilterBean == null || isApply(mCategoryId) || !mNeedBuy) {
            return;
        }

        mIsNeedShowDownloadAd = false;
    }

    private void onReward() {
        mIsNeedShowDownloadAd = false;
        {
            mWatchADBtn.setEnabled(false);
            mWatchADBtn.startAnim(new ChangeableRectButton.ChangeBtnListener() {
                @Override
                public void onAnimEnd() {
                    mWatchADBtn.setVisibility(View.GONE);
                    startDownload(true);
                }
            });
        }

        mNeedBuy = false;
    }

    boolean isTitleShow = true;
    private ObjectAnimator titleAnim;

    @Override
    public void onScrollChanged(ScrollView scrollView, int l, int t, int oldl, int oldt) {
        //RenderingView childAt = (RenderingView) mViewPager.findViewWithTag(mViewPager.getCurrentItem());
        ImageView childAt = mPagerAdapter.getCurrentView(mCurrentItem);
        if (childAt != null) {
            if (childAt instanceof RenderingView && ((RenderingView) childAt).getProgress() == 0) {
                ((RenderingView) childAt).startAnimator();
            }
        }
        /*if(t-oldt < 0){
            if(!isTitleShow){
                //下滑显示
                isTitleShow = true;
                titleAnim = ObjectAnimator.ofFloat(mCategoryTitle,"alpha",0f,1f);
                titleAnim.setDuration(300);
                titleAnim.start();
            }
        }else {
            if(isTitleShow){
                //上滑隐藏
                isTitleShow = false;
                titleAnim = ObjectAnimator.ofFloat(mCategoryTitle,"alpha",1f,0f);
                titleAnim.setDuration(300);
                titleAnim.start();
            }
        }*/

    }

    public static class DownloadListener implements IDownloadListener {
        private String mDownloadId;
        private WeakReference<FilterDetailActivity> mActivityRef;
        private String mFullActivityName;

        public DownloadListener(String categoryId, FilterDetailActivity activity) {
            mDownloadId = categoryId;
            mActivityRef = new WeakReference<>(activity);
            mFullActivityName = activity.getClass().getCanonicalName();
        }

        @Override
        public String getDownloadId() {
            return mDownloadId;
        }

        @Override
        public void onProgressUpdate(String downloadId, final int progress) {
            if (!TextUtils.isEmpty(downloadId) && mDownloadId.equals(downloadId)) {
                if (mActivityRef != null && mActivityRef.get() != null && !mActivityRef.get().isFinishing()) {
                    mActivityRef.get().runOnUiThread(new Runnable() {
                        @Override
                        public void run() {
                            mActivityRef.get().updateProgress(progress);
                        }
                    });
                }
            }
        }

        @Override
        public void onFailed(String downloadId) {
            if (!TextUtils.isEmpty(downloadId) && mDownloadId.equals(downloadId)) {
                if (mActivityRef != null && mActivityRef.get() != null && !mActivityRef.get().isFinishing()) {
                    mActivityRef.get().runOnUiThread(new Runnable() {
                        @Override
                        public void run() {
                            mActivityRef.get().onDwonloadFailed();
                        }
                    });
                }
            }
        }

        @Override
        public String getFullActivityName() {
            return mFullActivityName;
        }
    }

    private void updateProgress(int progress) {
        if (progress == 0) {
            progress = 1;
        }
        mProgressView.setProgress(progress);
        if (progress == 100) {
            endDownload(true);
        }
    }

    private void onDwonloadFailed() {
        postDelayed(new Runnable() {
            @Override
            public void run() {
                if (isFinishing()) {
                    return;
                }
                Toast.makeText(FilterDetailActivity.this, getResources().getString(R.string.filter_download_failed), Toast.LENGTH_SHORT).show();
                mDownloadBtn.setAlpha(1);
                mDownloadBtn.setScaleX(1);
                mDownloadBtn.setScaleY(1);
                mBottomIcon.setText(R.string.emoji_download1);
                mProgressView.setVisibility(View.GONE);
                downloadText.setVisibility(View.GONE);
                mDownloadBtn.setVisibility(View.VISIBLE);
            }
        }, TimeConstant.ONE_SEC);
    }

    @Override
    public void blur(final int position, boolean ready) {
        if (position == mCurrentItem && ready) {
            final String path;
            StoreOnlineBean storeOnlineBean = mStoreOnlineBeanList.get(mCurrentItem);
            String preview = storeOnlineBean.getPreview();
            String[] split = preview.split("#");
            if (split.length > 1) {
                preview = split[0];
            }
            path = preview;
            Bitmap cache = mBitmapCache.getBitmapFromCache(path);
            if (cache == null) {
                if (!tasks.containsKey(path)) {
                    final int currentItemTemp = mCurrentItem;
                    AsyncTask asyncTask = new AsyncTask<Object, Object, Bitmap>() {
                        @Override
                        protected Bitmap doInBackground(Object... params) {
                            Bitmap topImage = null;
                            {
                                try {
                                    topImage = GlideApp.with(FilterDetailActivity.this)
                                            .asBitmap()
                                            .load(path)
                                            .into(Target.SIZE_ORIGINAL, Target.SIZE_ORIGINAL)
                                            .get();
                                } catch (InterruptedException | ExecutionException e) {
                                    e.printStackTrace();
                                }
                            }
                            if (topImage == null) {
                                return null;
                            }
                            int width = topImage.getWidth();
                            int height = topImage.getHeight();
                            if (width == 0 || height == 0) {
                                return null;
                            }
                            int scaleRatio = 5;
                            Bitmap scaledBitmap = Bitmap.createScaledBitmap(topImage,
                                    width / scaleRatio,
                                    height / scaleRatio,
                                    false);
                            scaledBitmap = FastBlur.doBlur(scaledBitmap, 15, true);
                            mBitmapCache.addBitmapToCache(path, scaledBitmap, true, true);
                            return scaledBitmap;
                        }

                        @Override
                        protected void onPostExecute(Bitmap bitmap) {
                            if (bitmap != null && currentItemTemp == mCurrentItem) {
                                mBackGround.setImageBitmap(bitmap);
                            }
                            tasks.remove(path);
                        }
                    }.execute();
                    tasks.put(path, asyncTask);
                }
            } else {
                mBackGround.setImageBitmap(cache);
            }
        }
    }

    private void updateView() {
        blur(mCurrentItem, mPagerAdapter.isResReady(mCurrentItem));

        StoreOnlineBean storeOnlineBean = mStoreOnlineBeanList.get(mCurrentItem);
        String nameStr = storeOnlineBean.getName().replaceAll("[A-Z]", " $0");//正则替换注意“ $0”前面有个空格
        mFilterTitle.setText(nameStr);
        mFilterAuthor.setText(storeOnlineBean.getAuthor());
        mFilterDesc.setText(storeOnlineBean.getStory());
        if (mNeedBuy) {
            mWatchADBtn.setVisibility(View.VISIBLE);
        } else {
            mDownloadBtn.setVisibility(View.VISIBLE);
        }
    }

    private void initData() {
        mStoreOnlineBeanList = new ArrayList<>();
        mStoreOnlineBeanList.add(mFilterBean);

        StatisticsUtils.statisticsCustomStoreShow(StatisticsConstant.UMENG_CUSTOM_EVENT_FUNC_STORE_VALUE_CATEGORY_PAGE_SHOW + "_" + mFilterBean.getName());
    }

    @OnClick({R.id.iv_category_details_back, R.id.iv_category_download, R.id.progress_view, R.id.tv_filter_author, R.id.btn_watch_ad})
    public void onClick(View view) {
        switch (view.getId()) {
            case R.id.iv_category_details_back:
                onExist();
                break;
            case R.id.iv_category_download:
                onDownloadBtnClicked();
                break;
            case R.id.tv_filter_author:
                StoreOnlineBean storeOnlineBean = mStoreOnlineBeanList.get(mCurrentItem);
                mAppJump.open(storeOnlineBean.getAuthorUrl());
                break;
        }
    }

    private void onDownloadBtnClicked() {
        boolean isApply = StoreOnlineManager.getInstance().isInstalledByPkgName(mFilterBean, mFilterBean.getType());
        if (isApply) {
            if(isFreeToUnlock){//是订阅
                SVipController.showFunctionSubscribe(this,VIP_ENTRANCE_EDIT,StatisticsConstant.ENTRANCE_VALUE_FILTER,null);
//                SPDataManager.showTodayAllSubscribeMask();
//                StatisticsUtils.statisticGrowingIo(StatisticsConstant.EVENT_MP_BUTT_CLICK);
//                //跳转功能订阅页
//                SVipController.showFunctionSubscribe(this,VIP_ENTRANCE_EDIT,StatisticsConstant.ENTRANCE_VALUE_FILTER,
//                        new SVipController.OnSubscribeCloseListener() {
//                            @Override
//                            public void onSubscribeClose() {
//                                if ((SPDataManager.getTodayHasShowedAllSubscribeMaskCount() == 1)) {
//                                    //每天第一次关闭功能订阅页展示激励视频弹窗
//                                    DialogShow.showAdVideoDialog(DialogShow.InspireDialogEntrance.ENTRANCE_3, FilterDetailActivity.this, "", DialogStatistic.AdVideoWhere.VALUE_WHERE_MATERIAL, new IDialog.Listener() {
//                                        @Override
//                                        public void yes() {
//                                            //弹窗展示后,计入统计
//                                            SPDataManager.setIsShowAdvanceDialog(false);
//                                            StatisticsUtils.statisticGrowingIo(StatisticsConstant.EVENT_VIDEO_BUTTON_SHOW,
//                                                    StatisticsConstant.KEY_SHOW_TYPE, StatisticsConstant.VALUE_POPUP,
//                                                    StatisticsConstant.KEY_VIP_FUN, StatisticsConstant.VALUE_VIP_FUN_MATERIAL,
//                                                    StatisticsConstant.KEY_FILTER_NAME, mFilterBean.getName());
//
//                                        }
//                                    }, iAdVideoDialogListener2);
//                                }
//                            }
//                       });
                return;
            }
            if (PluginVersionUtil.verifyPluginVersion(this, BaseOnlineManager.STORE_FUNC_TYPE_FILTER, mFilterBean.getVersioncode())) {
                GalleryActivity.startGallerySelectImageToApplyFilter(this, mFilterBean.getPkgName(), "");
            }
        } else if (isDownloading()) {
            // TODO:正在下载，接口不支持暂停，先不处理
        } else {
            StatisticsUtils.statisicsCustom(StatisticsConstant.UMENG_CUSTOM_EVENT_PREFIX_FUNCTION, "download_state",
                    "event", "free_click");
            {
                // 启动下载
                startDownload(false);
//                RateGuide.showRate(this);
            }
        }
    }

//            IAdVideoDialogListener iAdVideoDialogListener2=new IAdVideoDialogListener() {
//                @Override
//                public void onSureClick() {
//                    StatisticsUtils.statisticGrowingIo(StatisticsConstant.EVENT_VIDEO_BUTTON_CLICK,
//                            StatisticsConstant.KEY_SHOW_TYPE, StatisticsConstant.VALUE_POPUP,
//                            StatisticsConstant.KEY_VIP_FUN, StatisticsConstant.VALUE_VIP_FUN_MATERIAL,
//                            StatisticsConstant.KEY_FILTER_NAME,mFilterBean.getName());
//                    SpUtils.obtain().save(EFFECT_NAME, mFilterBean.getName());
//                    DialogStatistic.adVideoSureClick(0);
//                }
//
//                @Override
//                public void onCancelClick() {
//                    DialogStatistic.adVideoCancelClick(0);
//                }
//
//
//                @Override
//                public void onCloseClick() {
//                    DialogStatistic.adVideoClose(0);
//                }
//            };


    private boolean mRewardAdLoading;
    private RewardAdManager mRewardAdManager;
    public RewardAdManager getRewardAdManager() {
        if (mRewardAdManager == null) {
            initAd();
        }
        return mRewardAdManager;
    }

    private void initAd() {
        mRewardAdManager = new RewardAdManager(this, AdKeyConstant.ADMOB_REWARDED_VIDEO,
                AdKeyConstant.UNITY_REWARDED_VIDEO, AdKeyConstant.REWARDED_VIDEO_ID);
        mRewardAdManager.setShowOverTimeMills(20000L);
        mRewardAdManager.setRewardListener(new RewardAdManager.RewardListener() {
            @Override
            public void onReward() {
                //激励完成,设置一次vip
                SPDataManager.setAdOneTimeVip(true);
                mRewardAdLoading = false;
                EventBus.getDefault().post(new FilterDetailUnlockSuccess(mFilterBean.getName()));
                DialogStatistic.adVideoUnlock(0);
                isFreeToUnlock=false;
                mBottomIcon.setText(R.string.button_apply);
            }

            @Override
            public void onFaild() {
                ToastUtil.showToast("loading advance fail");
                if (mRewardAdLoading) {
                    mRewardAdLoading = false;
                    if (CommercializeSDK.TestUser.isTestUser()) {
                        //激励完成，重走报告页逻辑
                        onSubscribeSuccessEvent(new SubscribeSuccessEvent(SubscribeSuccessEvent.SUB_TYPE_ONE_TIME));
                    }
                    ThreadPool.runUITask(new Runnable() {
                        @Override
                        public void run() {
                            ToastUtil.showToast(R.string.reward_ad_load_failed);
                        }
                    });
                }
            }

            @Override
            public void onTimeOut() {
                //超时按照激励处理
                onReward();
            }
        });

        //WiFi环境下，预加载广告视频
        if (NetworkUtils.isWifi() && !AppVipManager.isVip()){
            mRewardAdManager.loadRewardVideoAd();
        }
    }



    @Subscribe(threadMode = ThreadMode.MAIN)
    public void onSubscribeSuccessEvent(SubscribeSuccessEvent event) {
        isFreeToUnlock = false;
        mBottomIcon.setText(R.string.button_apply);
    }

    private void statisticsDownload() {
        StatisticsUtils.statisticsCustomStoreClick(StatisticsConstant.UMENG_CUSTOM_EVENT_FUNC_STORE_VALUE_CATEGORY_DOWNLOAD + "_" + mFilterBean.getName());
        SPDataManager.setDownloadCountToday(SPDataManager.getDownloadCountToday() + 1);
        SPDataManager.addDownloadCountOfDay();

        //统计banner下载
        String bannerFromWhere = getIntent().getStringExtra("bannerFromWhere");
        int position = getIntent().getIntExtra("bannerPosition", -1);
        if (!TextUtils.isEmpty(bannerFromWhere) && position != -1) {
            StatisticsUtils.statisticsBannerDownload(bannerFromWhere, position);
            StatisticsUtils.statisticsAllBannerDownload();
        }

        //通知栏更新
        NotifyStoreUpdateStatisticUtil.statisticDownload(mFilterBean.getName());
    }

    private void startDownload(boolean isBuy) {
        if (mIsNeedShowDownloadAd) {
            loadDownloadAd();
        }
        DownloadUtils.getInstance().startDownload(mFilterBean, BaseOnlineManager.STORE_FUNC_TYPE_FILTER);
        if (!isBuy) {
            mProgressView.setProgress(1);
            mProgressView.setVisibility(View.VISIBLE);
            downloadText.setVisibility(View.VISIBLE);
            //loadAnimStart();
        } else {
            if (mProgressView != null) {
                mProgressView.setProgress(1);
                mProgressView.setVisibility(View.VISIBLE);
                downloadText.setVisibility(View.VISIBLE);
            }
        }
        showDownloadDialog(mFilterBean);

        statisticsDownload();
    }

    private void endDownload(boolean success) {
        loadAnimEnd(success);
    }

    private boolean isDownloading() {
        boolean isDownloading = false;
        switch (DownloadUtils.getInstance().getDownloadStatus(mCategoryId)) {
            case DownloadUtils.DOWNLOAD_DEFAULT:
            case DownloadUtils.DOWNLOAD_END:
                isDownloading = false;
                break;
            case DownloadUtils.DOWNLOAD_CLICK:
            case DownloadUtils.DOWNLOAD_BING:
                isDownloading = true;
                break;

        }
        return isDownloading;
    }

    /**
     * 根据分类id判断是否已经在本地
     *
     * @param categoryId
     * @return
     */
    private boolean isApply(String categoryId) {
        boolean ret = false;
        if (!TextUtils.isEmpty(categoryId)) {
            ret = DataManager.getInstance().isExistFilterCategory(categoryId);
        }
        return ret;
    }

    private CharSequence getSpannableText(String originalText) {
        StringBuilder builder = new StringBuilder();
        for (int i = 0; i < originalText.length(); i++) {
            builder.append(originalText.charAt(i));
            if (i + 1 < originalText.length()) {
                builder.append("\u00A0");
            }
        }
        SpannableString finalText = new SpannableString(builder.toString());
        if (builder.toString().length() > 1) {
            for (int i = 1; i < builder.toString().length(); i += 2) {
                finalText.setSpan(new ScaleXSpan((spacing + 1) / 10), i, i + 1, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
            }
        }
        return finalText;
    }

    private void loadAnimStart() {
        valueAnimator = ValueAnimator.ofFloat(1f, 0f);
        valueAnimator.setDuration(400);
        valueAnimator.start();
        valueAnimator.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() {
            @Override
            public void onAnimationUpdate(ValueAnimator animation) {
                float value = (float) animation.getAnimatedValue();
                if (mDownloadBtn != null) {
                    mDownloadBtn.setAlpha(value);
                    mDownloadBtn.setScaleX(value);
                    mDownloadBtn.setScaleY(value);
                }
            }
        });
        valueAnimator.addListener(new AnimatorListenerAdapter() {
            @Override
            public void onAnimationEnd(Animator animation) {
                if (mProgressView != null) {
                    mProgressView.setProgress(1);
                    mProgressView.setVisibility(View.VISIBLE);
                    downloadText.setVisibility(View.VISIBLE);
                }
            }
        });
    }

    private void loadAnimEnd(boolean success) {
        mProgressView.setProgress(0);
        mProgressView.setVisibility(View.GONE);
        downloadText.setVisibility(View.GONE);
        mWatchADBtn.setVisibility(View.GONE);
        mWatchADBtn.setEnabled(true);

        mDownloadBtn.setVisibility(View.VISIBLE);

        if (success) {
            if(isIsShowVipView()){
                if( mFilterBean.isBuy() && AppVipManager.isVip()){
                    isFreeToUnlock=false;
                    mBottomIcon.setText(R.string.button_apply);
                }else{
                    isFreeToUnlock=true;
                    mBottomIcon.setText(R.string.button_free_to_unlock);
                    StatisticsUtils.statisticGrowingIo(StatisticsConstant.EVENT_MP_BUTT_SHOW);
                }
            }else{
                isFreeToUnlock=false;
                mBottomIcon.setText(R.string.button_apply);
            }
        } else {
            mBottomIcon.setText(R.string.emoji_download1);
        }
//        valueAnimator = ValueAnimator.ofFloat(0f, 1f);
//        valueAnimator.setDuration(400);
//        valueAnimator.start();
//        valueAnimator.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() {
//            @Override
//            public void onAnimationUpdate(ValueAnimator animation) {
//                float value = (float) animation.getAnimatedValue();
//                if (mDownloadBtn != null) {
//                    mDownloadBtn.setAlpha(value);
//                    mDownloadBtn.setScaleX(value);
//                    mDownloadBtn.setScaleY(value);
//                }
//            }
//        });
    }


    public static void startActivity(Activity context, StoreOnlineBean storeOnlineBean, int entrance, int storeEntrance) {
        if (checkToJumpToApk(context, storeOnlineBean, entrance)) {
            return;
        }
        Intent intent = new Intent(context, FilterDetailActivity.class);
        intent.putExtra(EXTRA_STORE_ONLINE_BEAN, storeOnlineBean);
        intent.putExtra("mEntrance", entrance);
        intent.putExtra(StoreConstant.store.EXTRA_STORE_ENTRANCE, storeEntrance);
//        context.startActivity(intent);
        context.startActivityForResult(intent, StoreConstant.REQUEST_CODE_START_DETAIL);
        context.overridePendingTransition(R.anim.left_in, R.anim.activity_no_animation);
    }

    public static void startActivity(Activity context, StoreOnlineBean storeOnlineBean, int entrance, int storeEntrance, String bannerFromWhere, int bannerPosition) {
        if (checkToJumpToApk(context, storeOnlineBean, entrance)) {
            return;
        }
        Intent intent = new Intent(context, FilterDetailActivity.class);
        intent.putExtra(EXTRA_STORE_ONLINE_BEAN, storeOnlineBean);
        intent.putExtra("mEntrance", entrance);
        intent.putExtra(StoreConstant.store.EXTRA_STORE_ENTRANCE, storeEntrance);
        intent.putExtra("bannerFromWhere", bannerFromWhere);
        intent.putExtra("bannerPosition", bannerPosition);
        context.startActivityForResult(intent, StoreConstant.REQUEST_CODE_START_DETAIL);
        context.overridePendingTransition(R.anim.left_in, R.anim.activity_no_animation);
    }


    private static boolean checkToJumpToApk(Activity activity, StoreOnlineBean storeOnlineBean, int entrance) {
        StoreOnlineBean categoryBean = null;
        if (storeOnlineBean.getType() == StoreOnlineBean.TYPE_CATEGORY) {
            categoryBean = storeOnlineBean;
        } else if (storeOnlineBean.getType() == StoreOnlineBean.TYPE_ITEM) {
            if (entrance == ENTRANCE_HOME) {
                categoryBean = HomeOnlineManager.getInstance().getParentBeanByModuleId(storeOnlineBean.getId());
            } else {
                categoryBean = StoreOnlineManager.getInstance().getFilterCategoryBeanByItem(storeOnlineBean);
            }
        }
        if (categoryBean == null
                || categoryBean.getType() != StoreOnlineBean.TYPE_CATEGORY
                || !categoryBean.isDownloadOnGP()) {
            return false;
        }
//        if (PackageReceiver.isPackageInstall(categoryBean.getPkgName())) {
//            Intent launchIntent = activity.getPackageManager().getLaunchIntentForPackage(categoryBean.getPkgName());
//            if (launchIntent != null) {
//                activity.startActivity(launchIntent);
//                return true;
//            }
//        }
        return false;
    }

    @Override
    public void finish() {
        super.finish();
        overridePendingTransition(R.anim.activity_no_animation, R.anim.right_out);
    }

    @Override
    protected void onDestroy() {
        super.onDestroy();
        destoryInListAd();
        destroySubstituteAd();
        if (blurTransformation != null) {
            blurTransformation = null;
        }
        if (mDownloadListener != null) {
            DownloadUtils.getInstance().removeListener(mDownloadListener);
        }
        if (valueAnimator != null) {
            valueAnimator.cancel();
        }
        for (String path : tasks.keySet()) {
            tasks.get(path).cancel(true);
        }
        tasks.clear();
        EventBus.getDefault().unregister(this);
//        ButterKnife.unbind(this);
        if (mAdProvider != null) {
            mAdProvider.destroy();
        }
    }


    private static final int REQUEST_CODE_SUBSTITUTE_AD = 222;


    public static final int REQUEST_CODE_REWARD_AD = 111;

    @Override
    protected void onActivityResult(int requestCode, int resultCode, Intent data) {
        super.onActivityResult(requestCode, resultCode, data);
        if (requestCode == REQUEST_CODE_REWARD_AD && resultCode == RESULT_OK) {
            onReward();
        } else if (requestCode == REQUEST_CODE_SUBSTITUTE_AD/* && resultCode == RESULT_OK*/) {
            // 启动广告界面后会立即执行onActivityResult并且resultCode为RESULT_CANCELED
            // 被启动activity在另一个task栈时候都会立即返回，比如被启动activity指定了taskAffinity
            // 应该是和以下两个东西有关，考虑到广告界面特殊性，而且不同系统情况不太一样，所以暂时不处理以下两个内容
            // android:launchMode="singleTask"
            // android:taskAffinity="com.superpro.ad"
            mSubstituteAdReady = false;
            onReward();
        } else if (requestCode == PermissionUtil.PERMISSION_REQ_CODE) {
            EventBus.getDefault().post(new CheckFloatWindowPermissionEvent());
        }
    }

    private void loadDownloadAd() {
        String unitId = AdKeyConstant.InappAdPlacementID.DOWNLOAD_ID;
        final int adTouchType = AdDisplay.AdTouchType.DEFAULT;
        String sceneName = "vipdownload";
        if(mAdProvider == null) {
            mAdProvider = AdProvider.newProvider(sceneName, unitId, -1);
            mAdProvider.addStatisticsInfo(StatisticsConstant.KEY_MAIN_PAGE_FUN, StatisticsConstant.ENTRANCE_VALUE_FILTER);
            mAdProvider.setOnAdListener(new AdProvider.OnAdListener() {
                @Override
                public void onAdLoadFinish(String cacheKey) {
                    if (mAdProvider == null) {
                        AdProvider.statisticsNoShowAd(sceneName, AdProvider.REASON_PAGE_NO_SHOWING);
                    }

                    if (mDownloadAdLayout != null) {
                        if (!TextUtils.isEmpty(adCacheKey)) {
                            AdManager.getInstance().destoryAd(adCacheKey);
                        }
                        boolean isAdValid = true;
                        if (!mAdProvider.hasAd()) {
                            isAdValid = false;
                        }

                        if (!isAdValid) {
                            mAdProvider.statisticsNoShowAd(AdProvider.REASON_NO_VALID_AD);
                            return;
                        } else {
                            adCacheKey = mAdProvider.getAdCacheKey();
                        }
                    } else {
                        AdProvider.statisticsNoShowAd(sceneName, AdProvider.REASON_PAGE_NO_SHOWING);
                    }
                }

                @Override
                public void onAdLoadFailure(String err) {

                }

                @Override
                public void onAdClicked(String cacheKey) {
//                    if(mBottomDatas == null || mBottomRecyclerAdapter == null) {
//                        return;
//                    }
//                    if (index >= 0 && index < mBottomDatas.size()) {
//                        mBottomDatas.remove(index);
//                        mBottomRecyclerAdapter.notifyDataSetChanged();
//                        return;
//                    }
//                    IItemBean needDelBean = null;
//                    for (IItemBean bean : mBottomDatas) {
//                        if (bean instanceof AdItemBean) {
//                            if (TextUtils.equals(cacheKey, ((AdItemBean) bean).getAdCacheKey())) {
//                                needDelBean = bean;
//                                break;
//                            }
//                        }
//                    }
//                    if (needDelBean != null) {
//                        mBottomDatas.remove(needDelBean);
//                        mBottomRecyclerAdapter.notifyDataSetChanged();
//                    }
                }

                @Override
                public void onAdImpression(String cacheKey) {

                }
            });
        }
        if (!mAdProvider.hasAd()) {
            mAdProvider.loadAd();
        }
    }

    @Subscribe(threadMode = ThreadMode.MAIN)
    public void onDownloadFinish(DownloadFinishEvent event) {
        StoreOnlineBean downloadBean = event.getDownloadBean();
//        showDownloadDialog(downloadBean);
    }

    private void showDownloadDialog(final StoreOnlineBean downloadBean) {
        if (downloadBean == null) {
            if (DebugUtil.isDebuggable() || TestUser.isTestUser()) {
                RLog.v(this.getClass().getSimpleName(), "store_download, " + downloadBean.getName() + " bean not equals");
            }
            return;
        }
        if (!mIsNeedShowDownloadAd) {
            if (DebugUtil.isDebuggable() || TestUser.isTestUser()) {
                RLog.v(this.getClass().getSimpleName(), "store_download, " + downloadBean.getName() + " bean is not need ad");
            }
            return;
        }

        if (TextUtils.isEmpty(adCacheKey) || !mAdProvider.hasAd()) {
            return;
        }
        AdItemBean adItemBean = new AdItemBean(adCacheKey);
        adItemBean.setNeedLimitAdHeight(true);
        adItemBean.setAdTouchType(AdDisplay.AdTouchType.DEFAULT);

        View adView = adItemBean.createAdView(R.layout.ad_filter_download_view);

        ViewGroup downloadAdLayout = mDownloadAdLayout.findViewById(R.id.download_ad_layout);
        downloadAdLayout.removeAllViews();
        downloadAdLayout.addView(adView);
        mDownloadAdLayout.setVisibility(View.VISIBLE);
        mDownloadAdMask.setVisibility(View.VISIBLE);
        mDownloadAdLayout.findViewById(R.id.ic_close).setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                mDownloadAdLayout.setVisibility(View.GONE);
                mDownloadAdMask.setVisibility(View.GONE);
            }
        });
        mDownloadAdMask.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                //拦截点击，不做处理
            }
        });
    }


    private void destroySubstituteAd() {
        mSubstituteAdKey = null;
    }

    private boolean isInListAdLoading = false;


    private void initInListAd() {
//        if (mLayoutAdItemBean != null && mLayoutAdItemBean.hasAd()) {
//            return;
//        }
//        if (isInListAdLoading) {
//            return;
//        }
//        mAdLayout.setVisibility(View.GONE);
//        isInListAdLoading = true;
//        final String categoryName = mFilterBean.getName();
//        final Context context = ComponentContext.getContext();
//        String unitId = AdKeyConstant.AdKeyPlacementID.PLACEMENTID_NATIVE_FILTER_DETAIL_LAYOUT;
//        final String sceneName = "category_layout";
//
//        final int adTouchType;
//        adTouchType = AdDisplay.AdTouchType.DEFAULT;
//
//
//        if (mInListAdProvider == null) {
//            mInListAdProvider = new AdProvider(sceneName, unitId, -1);
//            mInListAdProvider.setStatisticsInfo("name", categoryName);
//        }
//        final AdManager.AdRequest request = AdManager.getInstance().createRequest();
//        request.setSceneName(sceneName)
//                .addAllNativeByDefault(this);
//        mInListAdProvider.setOnAdListener(new AdProvider.OnAdListener() {
//
//            @Override
//            public void onAdLoadFinish(String cacheKey) {
//                isInListAdLoading = false;
//                if (mInListAdProvider == null) {
//                    AdProvider.statisticsNoShowAd(sceneName, AdProvider.REASON_PAGE_NO_SHOWING);
//                    return;
//                }
//                if (mAdLayout == null) {
//                    String key = request.getKey();
//                    AdManager.getInstance().destoryAd(key);
//                    AdProvider.statisticsNoShowAd(sceneName, AdProvider.REASON_PAGE_NO_SHOWING);
//                    return;
//                }
//
//                String layoutAdCacheKey = mInListAdProvider.getAdCacheKey();
//                boolean isAdValid = true;
//                if (TextUtils.isEmpty(layoutAdCacheKey)) {
//                    String key = request.getKey();
//                    AdManager.getInstance().destoryAd(key);
//                    return;  //获取的广告为空，认为界面已经销毁
//                } else if (!AdManager.getInstance().isValid(layoutAdCacheKey)) {
//                    isAdValid = false;
//                }
//
//                if (!isAdValid) {
//                    mInListAdProvider.statisticsNoShowAd(AdProvider.REASON_NO_VALID_AD);
//                    return;
//                }
//
//                mLayoutAdItemBean = new AdItemBean(layoutAdCacheKey);
//                mLayoutAdItemBean.setAdTouchType(adTouchType);
//
//                mAdLayout.removeAllViews();
//                mAdLayout.setVisibility(View.VISIBLE);
//
//                mAdView = mLayoutAdItemBean.createAdView(R.layout.ad_filter_banner_view);
//
//                BaseNativeAdView baseNativeView = mLayoutAdItemBean.getBaseNativeView();
//                AbsAd thirdPartyAd = baseNativeView.getThirdPartyAd();
//                if (thirdPartyAd instanceof IViewAd) {
//                    baseNativeView.setBackgroundColor(Color.TRANSPARENT);
//                }
//
//                mAdLayout.addView(mAdView);
//                CubicBezierInterpolator cubicBezierInterpolator = new CubicBezierInterpolator(0, 1.06, .73, 1);
//
//                TranslateAnimation adLayoutAnimation = new TranslateAnimation(
//                        Animation.RELATIVE_TO_SELF, 1.0f,
//                        Animation.RELATIVE_TO_SELF, 0.0f,
//                        Animation.RELATIVE_TO_SELF, 0.0f,
//                        Animation.RELATIVE_TO_SELF, 0.0f);
////        adLayoutAnimation.setStartTime(System.currentTimeMillis() + 500);
//                adLayoutAnimation.setDuration(800);
//                adLayoutAnimation.setInterpolator(cubicBezierInterpolator);
//                mAdLayout.startAnimation(adLayoutAnimation);
//            }
//
//            @Override
//            public void onAdLoadFailure(String err) {
//                isInListAdLoading = false;
//            }
//
//            @Override
//            public void onAdClicked(String cacheKey) {
//                //点击之后不再重加载
////                initInListAd();
//            }
//
//            @Override
//            public void onAdImpression(String cacheKey) {
//
//            }
//
//        });
//
//        mInListAdProvider.loadAd(request);
    }

    private void destoryInListAd() {
//        if (mLayoutAdItemBean != null) {
//            mLayoutAdItemBean.destory();
//            mLayoutAdItemBean = null;
//        }
//        if (mInListAdProvider != null) {
//            mInListAdProvider.destroy();
//            mInListAdProvider = null;
//        }
    }

    @Subscribe(threadMode = ThreadMode.MAIN)
    public void refreshFilterCategory(final RefreshFilterCategory event) {
        if (mFilterBean != null) {
            if (!TextUtils.isEmpty(event.delCategoryId) && mCategoryId.equals(event.delCategoryId)) {
                updateUIOfUninstall();
            } else {
                if (isApply(mCategoryId)) {
                    updateUIOfInstall();
                }
            }
        }
    }

    private void updateUIOfInstall() {
        if(isIsShowVipView()){
            if( mFilterBean.isBuy() && AppVipManager.isVip()){
                isFreeToUnlock=false;
                mBottomIcon.setText(R.string.button_apply);
            }else{
                isFreeToUnlock=true;
                mBottomIcon.setText(R.string.button_free_to_unlock);
                StatisticsUtils.statisticGrowingIo(StatisticsConstant.EVENT_MP_BUTT_SHOW);

            }
        }else{
            isFreeToUnlock=false;
            mBottomIcon.setText(R.string.button_apply);
        }

        mDownloadBtn.setVisibility(View.VISIBLE);
        mProgressView.setVisibility(View.GONE);
        downloadText.setVisibility(View.GONE);
        mWatchADBtn.setVisibility(View.GONE);
    }

    private void updateUIOfUninstall() {
        /*if (mFilterBean.isDownloadOnGP()){
            if (PackageReceiver.isPackageInstall(mFilterBean.getPkgName())) {
                mBottomIcon.setImageResource(R.drawable.ic_store_apply);
                mDownloadBtn.setVisibility(View.VISIBLE);
                mProgressView.setVisibility(View.GONE);
                mWatchADBtn.setVisibility(View.GONE);
            } else {
                mWatchADBtn.setGPType();
                mWatchADBtn.setVisibility(View.VISIBLE);
                mDownloadBtn.setVisibility(View.GONE);
                mProgressView.setVisibility(View.GONE);
            }
        } else */
        {
            {
                mBottomIcon.setText(R.string.emoji_download1);
                mDownloadBtn.setVisibility(View.VISIBLE);
                mProgressView.setVisibility(View.GONE);
                downloadText.setVisibility(View.GONE);
                mWatchADBtn.setVisibility(View.GONE);
            }
        }
    }

    @Override
    public void onBackPressed() {
        super.onBackPressed();
        onExist();
    }

    public void onExist() {
        //通知栏更新
        NotifyStoreUpdateStatisticUtil.clear();
        finish();
    }

}
